// $Id: Reputation.java 13 2009-02-24 12:33:10Z joakim.waltersson $
package se.waltersson.wowarmory.page;

import java.util.HashMap;
import java.util.Map;


/**
 * @author Joakim Waltersson
 * @version $Revision: 13 $ $Date: 2009-02-24 12:33:10 +0000 (Tue, 24 Feb 2009) $
 */
public class Reputation extends ArmoryPage {
    // Burning Crusade
    public static final String CENARION_EXPEDITION = "cenarionexpedition";
    public static final String HONOR_HOLD = "honorhold";
    public static final String LOWER_CITY = "lowercity";
    public static final String THE_SHATAR = "thesha'tar";
    public static final String KEEPERS_OF_TIME = "keepersoftime";
    public static final String THE_VIOLET_EYE = "thevioleteye";
    public static final String SHATTERED_SUN = "shatteredsunoffensive";
    public static final String ALDOR = "thealdor";
    public static final String SCRYERS = "thescryers";
    
    // Wrath of the Lich King
    public static final String ARGENT_CRUSADE = "argentcrusade";
    public static final String KIRIN_TOR = "kirintor";
    public static final String THE_KALU_AK = "thekalu'ak";
    public static final String THE_WYRMREST_ACCORD = "thewyrmrestaccord";
    public static final String THE_SONS_OF_HODIR = "thesonsofhodir";
    
    private Map<String, ParsedNode> reputations;

    public Reputation(String realm, String charName) {
        super(realm, charName);
        reputations = new HashMap<String, ParsedNode>();
    }

    private static final String pageName = "character-reputation.xml";

    /* (non-Javadoc)
     * @see se.waltersson.wowarmory.ArmoryPage#getPath()
     */
    public String getQuery() {
        return pageName + getQueryParameters();
    }

    @Override
    protected void parse() {
        reputations = getMap("//faction", "key",
            new StringNodeParser("reputation"));
    }
    
    public long getReputation(String faction) {
        ParsedNode parsedNode = reputations.get(faction);
        if (parsedNode == null) {
            return 0;
        }
        String s = parsedNode.toString();
        if (s == null) {
            return 0;
        }
        return Long.parseLong(s);
    }
}
